package com.ThreadandAsyn;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.examplee.username.httpfrist_01.R;

import java.util.List;

/**
 * Created by usernamee on 2017/8/19.
 */

public class NewAdapter extends BaseAdapter {
List<NewBean> mList;
    LayoutInflater inflater;
    public NewAdapter(List<NewBean> mList, Context context){
        mList=mList;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder viewholder=null;
        if (convertView==null)
        {
            viewholder=new Viewholder();
            convertView=inflater.inflate(R.layout.item_layout,null);
            viewholder.ivicon= (ImageView) convertView.findViewById(R.id.iv_icon);
            viewholder.tvcontent= (TextView) convertView.findViewById(R.id.tv_content);
            viewholder.tvtitle= (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(viewholder);
        }else {
            viewholder= (Viewholder) convertView.getTag();
        }
        viewholder.ivicon.setImageResource(R.drawable.imgasyn);
        viewholder.tvcontent.setText(mList.get(position).newsContent);
        viewholder.tvtitle.setText(mList.get(position).newsTitle);

        return convertView;
    }

    class Viewholder{
        TextView tvtitle,tvcontent;
        ImageView ivicon;

    }
}
